library(knitr)
library(oSCR)
#library(scrbook)

options(width=120)
options(width.cutoff=80)
opts_chunk$set(prompt = FALSE, comment = NA, mysize=TRUE, size="\\scriptsize")
hook1 <- function(x){ gsub("```\n*```r*\n*", "", x) }
hook2 <- function(x){ gsub("```\n+```\n", "", x) }
knit_hooks$set(document = hook2)
knitr::knit_hooks$set(mysize = function(before, options, envir) {
  if (before) 
    return(options$size)
})

What is \texttt{oSCR}?

The \textcolor{mLightBrown}{\texttt{o}} is for open

\begin{itemize} \item<1-> built upon various functions in \texttt{scrbook}
\item<2-> an editable and evolving code base \item<3-> a community of contributors
\begin{itemize} \item<3-> \textcolor{gray}{\textit{contributing}} ideas \item<3-> \textcolor{gray}{\textit{contributing}} problems \item<3-> \textcolor{gray}{\textit{contributing}} solutions \item<3-> \textcolor{gray}{\textit{contributing}} code \end{itemize} \item<4-> a philosophy of 'parallel publishing' \begin{itemize} \item<4-> \textcolor{gray}{\textit{increase}} transparency \item<4-> \textcolor{gray}{\textit{increase}} accessibility \end{itemize} \end{itemize}

\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (10,4) {\includegraphics[height=1.2in]{scrbook.png}}; \node[inner sep=0pt] (one) at (10,0.91) {\includegraphics[height=0.8in]{oSCR.png}}; \end{tikzpicture}

What is \texttt{oSCR}?

$\ldots$ more about \texttt{oSCR}

\begin{itemize} \item<1-> one of several ways to analyze SCR data \begin{itemize} \item<1-> alternative (\textit{not} substitute) to \texttt{secr} \item<1-> (see Dan's lecture tomorrow) \item<1-> alternative to Bayesian analysis \end{itemize} \item<2-> likelihood based - has advantages \begin{itemize} \item<2-> \textcolor{gray}{\textit{advantage}} speed \item<2-> \textcolor{gray}{\textit{advantage}} model selection methods \item<2-> \textcolor{gray}{\textit{advantage}} cost surface modeling \item<2-> \textcolor{gray}{\textit{advantage}} user friendly \end{itemize} \end{itemize} \begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (10,0.175) {\includegraphics[height=0.8in]{oSCR.png}}; \end{tikzpicture}

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist,       # spatial encounter histories
                    traps,         # trap coordinates
                    trapCovs,      # trap level covariates
                    indCovs,       # sex data
                    trapOperation, # binary operation indicator
                    type)          # data format type

\normalsize \texttt{?make.scrFrame}

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist,       # spatial encounter histories
                    traps,         # trap coordinates
                    trapCovs,      # trap level covariates
                    indCovs,       # sex data
                    trapOperation, # binary operation indicator
                    type)          # data format type

\normalsize \texttt{caphist} ($y_{ijk}$):

\texttt{caphist}

\scalebox{0.6}{ \begin{tikzpicture}[overlay] \matrix[draw=none,inner sep=0pt] (C) at (5,-3)[matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=0.2,text height=1ex,nodes in empty cells] { 3 \& 2 \& 0 \& 0 \& \cdots \& \& \& \& \ 1 \& 0 \& 1 \& \cdots \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \vdots \& 4 \ \& \& \& \& \& \& \& 3 \& 0 \ \& \& \& \& \& \& \& 1 \& 1 \ }; \fill[gray,opacity=.2] (C-2-1.south west) -- (C-1-1.north west) -- (C-1-9.north east) -- (C-11-9.south east) -- (C-11-8.south west) -- (C-3-8.north west) -- (C-2-1.south west); \draw[opacity=0.2] (C-2-1.south west) -- (C-1-1.north west)--(C-1-9.north east)--(C-11-9.south east)--(C-11-8.south west);

\matrix[draw=none,inner sep=0pt] (D) at (4,-4)[matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=0.35,text height=1ex,nodes in empty cells] { 2 \& 2 \& 1 \& 0 \& \cdots \& \& \& \& \ 4 \& 0 \& 0 \& \cdots \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \vdots \& 0 \ \& \& \& \& \& \& \& 0 \& 2 \ \& \& \& \& \& \& \& 1 \& 0 \ %%%%%% 8 }; \fill[gray,opacity=.35] (D-3-1.south west) -- (D-1-1.north west) -- (D-1-9.north east) -- (D-11-9.south east) -- (D-11-8.south west) -- (D-4-8.north west) -- (D-3-1.south west); \draw[opacity=0.35] (D-3-1.south west) -- (D-1-1.north west)--(D-1-9.north east)--(D-11-9.south east)--(D-11-8.south west);

\matrix[draw,inner sep=0pt] (E) at (3,-5) [matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=1,fill=gray,text height=1ex,nodes in empty cells] { 1 \& 3 \& 0\& 1\& \cdots \& \& \& \& \ 6 \& 1 \& 2\& \& \& \& \& \& \ 0 \& 0 \& \& \& \& \& \& \& \ 3 \& \& \& \& \& \& \& \& \ \vdots \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \&\vdots \ \& \& \& \& \& \& \& \& 3 \ \& \& \& \& \& \& \& 0 \& 0 \ \& \& \& \& \& \cdots \& 0 \& 0 \& 0 \ };%

\draw[] (E-6-5) node {\large\textcolor{green}{$\boldsymbol{y_{i,j,r}}$}}; \draw[] (E-7-5) node {\large\textcolor{green}{counts}};

%Trap \draw[] (C-1-1.north east) node[above left] {\textbf{Trap = 1}}; \draw[] (C-1-9.north) node[above] {\textbf{$J$}}; \draw[->, thick] ([yshift=7.5]C-1-1.north east) -- ([yshift=7.5]C-1-9.north west);

%Ind \draw[] (E-1-1.west) node[left, yshift=2] {\textbf{Ind. = 1}}; \draw[] (E-11-1.west) node[left, yshift=2] {\textbf{$n_{obs}$}}; \draw[->, thick] ([xshift=-7.5]E-2-1.west) -- ([xshift=-7.5]E-10-1.west);

\draw[] (E-11-9.south) node[below] {\textbf{Occassion = 1}}; \draw[] (C-11-9.east) node[right, xshift=2ex] {\textbf{$K$}}; \draw[->, thick] ([xshift=2ex]E-11-9.south east) -- ([xshift=2ex]C-11-9.south east);

\matrix[draw=none,inner sep=0pt] (C) at (15,-3)[matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=0.2,text height=1ex,nodes in empty cells] { 1\& 1\& 0\& 0 \& \cdots \& \& \& \& \ 1\& 0\& 1\& \cdots \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \vdots \& 1 \ \& \& \& \& \& \& \& 1 \& 0 \ \& \& \& \& \& \& \& 1 \& 1 \ %%%%%% 11 }; \fill[gray,opacity=.2] (C-2-1.south west) -- (C-1-1.north west) -- (C-1-9.north east) -- (C-11-9.south east) -- (C-11-8.south west) -- (C-3-8.north west) -- (C-2-1.south west); \draw[opacity=0.2] (C-2-1.south west) -- (C-1-1.north west)--(C-1-9.north east)--(C-11-9.south east)--(C-11-8.south west);

\matrix[draw=none,inner sep=0pt] (D) at (14,-4)[matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=0.35,text height=1ex,nodes in empty cells] { 1 \& 1\& 1\& 0 \& \cdots \& \& \& \& \ 1 \& 0\& 0\& \cdots \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \vdots \& 0 \ \& \& \& \& \& \& \& 0 \& 1 \ \& \& \& \& \& \& \& 1 \& 0 \ %%%%%% 8 }; \fill[gray,opacity=.35] (D-3-1.south west) -- (D-1-1.north west) -- (D-1-9.north east) -- (D-11-9.south east) -- (D-11-8.south west) -- (D-4-8.north west) -- (D-3-1.south west); \draw[opacity=0.35] (D-3-1.south west) -- (D-1-1.north west)--(D-1-9.north east)--(D-11-9.south east)--(D-11-8.south west);

\matrix[draw,inner sep=0pt] (E) at (13,-5) [matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=1,fill=gray,text height=1ex,nodes in empty cells] { 1 \& 1 \& 0 \& 1\& \cdots \& \& \& \& \ 1 \& 1 \& 1 \& \& \& \& \& \& \ 0 \& 0 \& \& \& \& \& \& \& \ 1 \& \& \& \& \& \& \& \& \ \vdots \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \& 1 \ \& \& \& \& \& \& \& 0 \& 0 \ \& \& \& \& \& \cdots \& 0 \& 0 \& 0 \ };%

\draw[] (E-6-5) node {\large\textcolor{green}{$\boldsymbol{y_{i,j,r}}$}}; \draw[] (E-7-5) node {\large\textcolor{green}{detections}};

%Trap \draw[] (C-1-1.north east) node[above left] {\textbf{Trap = 1}}; \draw[] (C-1-9.north) node[above] {\textbf{$J$}}; \draw[->, thick] ([yshift=7.5]C-1-1.north east) -- ([yshift=7.5]C-1-9.north west);

%Ind \draw[] (E-1-1.west) node[left, yshift=2] {\textbf{Ind. = 1}}; \draw[] (E-11-1.west) node[left, yshift=2] {\textbf{$n_{obs}$}}; \draw[->, thick] ([xshift=-7.5]E-2-1.west) -- ([xshift=-7.5]E-10-1.west);

\draw[] (E-11-9.south) node[below] {\textbf{Occassion = 1}}; \draw[] (C-11-9.east) node[right, xshift=2ex] {\textbf{$K$}}; \draw[->, thick] ([xshift=2ex]E-11-9.south east) -- ([xshift=2ex]C-11-9.south east); \end{tikzpicture} }

\texttt{caphist}

yarr <- array(rbinom(3*10*3,1,0.4),c(3,10,3))
yarr

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist,       # spatial encounter histories
                    traps,         # trap coordinates
                    trapCovs,      # trap level covariates
                    indCovs,       # sex data
                    trapOperation, # binary operation indicator
                    type)          # data format type

\normalsize \texttt{traps}:

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist,       # spatial encounter histories
                    traps,         # trap coordinates
                    trapCovs,      # trap level covariates
                    indCovs,       # sex data
                    trapOperation, # binary operation indicator
                    type)          # data format type

\normalsize \texttt{trapCovs}:

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist,       # spatial encounter histories
                    traps,         # trap coordinates
                    trapCovs,      # trap level covariates
                    indCovs,       # sex data
                    trapOperation, # binary operation indicator
                    type)          # data format type

\normalsize \texttt{indCovs}:

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist,       # spatial encounter histories
                    traps,         # trap coordinates
                    trapCovs,      # trap level covariates
                    indCovs,       # sex data
                    trapOperation, # binary operation indicator
                    type)          # data format type

\normalsize \texttt{trapOperation}:

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist,       # spatial encounter histories
                    traps,         # trap coordinates
                    trapCovs,      # trap level covariates
                    indCovs,       # sex data
                    trapOperation, # binary operation indicator
                    type)          # data format type

\normalsize \texttt{type}:

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist       = list(ch),
                    traps         = list(tr),
                    trapCovs      = list(list(tc1,tc2,tc3)), #k=3      
                    indCovs       = list(ic),
                    trapOperation = list(to),
                    type          = "SCR")

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist       = list(ch1, ch2),
                    traps         = list(tr1, tr1),
                    trapCovs      = list(list(tc1.1,tc1.2,tc1.3),
                                         list(tc2.1,tc2.2,tc2.3)), #k=3      
                    indCovs       = list(ic1, ic2),
                    trapOperation = list(to1,to2),
                    type          = "SCR")

\texttt{oSCR} - Data organization and structure

scrFrame: the main data object for model fitting:

sf <- make.scrFrame(caphist       = list(ch1, ch2, ch3),
                    traps         = list(tr1, tr1, tr3),
                    trapCovs      = list(list(tc1.1,tc1.2,tc1.3),
                                         list(tc2.1,tc2.2,tc2.3),
                                         list(tc3.1,tc3.2,tc3.3)), #k=3      
                    indCovs       = list(ic1, ic2, ic3),
                    trapOperation = list(to1,to2, to3),
                    type          = "SCR")

\normalsize

$\ldots$ and so on and so forth

\texttt{oSCR} - Data organization and structure

Data formats:

Exploring the \texttt{scrFrame}

Lets look at some real data

\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (9,-1) {\includegraphics[height=2.8in]{sampling.png}}; \node[inner sep=0pt] (one) at (4,-2) {\includegraphics[height=1.75in]{mark.png}}; \end{tikzpicture}

Exploring the \texttt{scrFrame}

library(oSCR)
data(rbs)
ls()

[1] "rbs.sf" "rbs.ss"
library(oSCR)
data(rbs)

\normalsize

Exploring the \texttt{scrFrame}

library(oSCR)
data(rbs)
rbs.sf

Subsetting the \texttt{scrFrame}

sf.sub <- subFrame(scrFrame, # the scrFrame to be subsetted
                   subs)     # the index/indices to be kept

Subsetting the \texttt{scrFrame}

sf.sub <- subFrame(scrFrame = rbs.sf, 
                   subs = c(2,4))
sf.sub

Subsetting the \texttt{scrFrame}

sf.sub <- subFrame(scrFrame = rbs.sf, 
                   subs = c(2,4))
sf.sub

\texttt{oSCR} - Data organization and structure

State space definition is extremely important

\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (5,-1.5) {\includegraphics[height=1.2in]{sbuf.png}}; \end{tikzpicture}

\texttt{oSCR} - Data organization and structure

ssDF: the state space data object (\textbf{s}tate \textbf{s}pace {\textbf{d}ata \textbf{f}rame):

\texttt{oSCR} - Data organization and structure

Making the ssDF object requires constructing a list of data frames

ssDF <- list(ss1,  # dataframe for session 1
             ss2,  # dataframe for session 2
             ss3,  # dataframe for session 3
             ss4)  # dataframe for session 4

Exploring the \texttt{ssDF}

Let's work with the salamander state space object:

str(rbs.ss, give.attr=FALSE)

Exploring the \texttt{ssDF}

Sub setting ssDF is easily done:

# sub setting ssDF is easy:
ss.sub <- rbs.ss[c(1,2)]

Exploring the \texttt{ssDF}

Sub setting ssDF is easily done:

# sub setting ssDF is easy:
ss.sub <- rbs.ss[c(1,2)]
str(ss.sub, give.attr=FALSE)

Exploring the \texttt{ssDF}

We can plot the object

par(mfrow=c(2,2), oma=c(0,0,0,0),mar=c(4,4,2,2))
par(mfrow=c(1,4)) #4 sessions
plot.ssDF(rbs.ss)

Exploring the \texttt{ssDF}

We can plot the object with the traps

par(mfrow=c(1,4)) #4 sessions
plot.ssDF(rbs.ss, scrFrame=rbs.sf)

Constructing a \texttt{ssDF}

If no interest in assessing spatial variation in density

ssDF <- make.ssDF(scrFrame,  # an scrFRame objects
                  buffer,    # a buffer witdh (around traps!)
                  res)       # the  distance between S points

Constructing a \texttt{ssDF}

par(mfrow=c(1,2))
ssDF <- make.ssDF(scrFrame = sf.sub,
                  buffer = 1,
                  res = 1)
plot(ssDF, sf.sub)

Constructing a \texttt{ssDF}

ssDF <- make.ssDF(scrFrame = sf.sub,
                  buffer = 5,
                  res = 0.5)
plot(ssDF, sf.sub)

\texttt{oSCR} - Model fitting

With an scrFrame and ssDF object, we can start fitting models uning the fitting function oSCR.fit()

mod <- oSCR.fit(model,       # model formulation
                scrFrame,    # the scrFrame object
                ssDF,        # the ssDF object
                encmod,      # the detection function model
                trimS,       # local evaluation distance
                start.vals,  # parameter starting values
                predict,     # predict desnity
                ...)         # a few other options

\texttt{oSCR} - Model fitting

mod <- oSCR.fit(model,       # model formulation
                scrFrame,    # the scrFrame object
                ssDF,        # the ssDF object
                encmod,      # the detection function model
                trimS,       # local evaluation distance
                start.vals,  # parameter starting values
                predict,     # predict desnity
                ...)         # a few other options

\normalsize \texttt{model}:

\texttt{oSCR} - Model fitting

mod <- oSCR.fit(model,       # model formulation
                scrFrame,    # the scrFrame object
                ssDF,        # the ssDF object
                encmod,      # the detection function model
                trimS,       # local evaluation distance
                start.vals,  # parameter starting values
                predict,     # predict desnity
                ...)         # a few other options

\normalsize \texttt{model}:

\texttt{oSCR} - model choices

Varaition in \textcolor{blue}{density} (D ~)

D ~ 1             # null model, constant density
D ~ session       # density varies by session
D ~ "covariate"   # density varies by spatially indexed covariates

\normalsize

\texttt{oSCR} - model choices

Varaition in \textcolor{blue}{detection} (p0 ~)

p0 ~ 1            # null model, constant p (M0)
p0 ~ t            # occasion specific p (Mt)
p0 ~ b            # behavioural response (Mb)
p0 ~ sex          # p varies by sex
p0 ~ session      # p varies by session
p0 ~ "covariate"  # p varies by trap level covariates

\normalsize

\texttt{oSCR} - model choices

Varaition in \textcolor{blue}{sigma} (sig ~)

sig ~ 1           # null model, constant sigma
sig ~ sex         # sex-specific sigma 
sig ~ session     # session-specific sigma

\normalsize

\texttt{oSCR} - Model fitting

mod <- oSCR.fit(model,       # model formulation
                scrFrame,    # the scrFrame object
                ssDF,        # the ssDF object
                encmod,      # the detection function model
                trimS,       # local evaluation distance
                start.vals,  # parameter starting values
                predict,     # predict desnity
                ...)         # a few other options

\normalsize \texttt{scrFrame} and \texttt{ssDF}:

\texttt{oSCR} - Model fitting

mod <- oSCR.fit(model,       # model formulation
                scrFrame,    # the scrFrame object
                ssDF,        # the ssDF object
                encmod,      # the detection function model
                trimS,       # local evaluation distance
                start.vals,  # parameter starting values
                predict,     # predict desnity
                ...)         # a few other options

\normalsize \texttt{encmod}:

A character defining which enccounter model to be used

\texttt{oSCR} - Model fitting

mod <- oSCR.fit(model,       # model formulation
                scrFrame,    # the scrFrame object
                ssDF,        # the ssDF object
                encmod,      # the detection function model
                trimS,       # local evaluation distance
                start.vals,  # parameter starting values
                predict,     # predict desnity
                ...)         # a few other options

\normalsize \texttt{trimS}:

\textit{trimming} the state space

sf1 <- subFrame(rbs.sf,1)
ss1 <- rbs.ss[1]
par(ask=TRUE)
mod <- oSCR.fit(scrFrame=sf1, ssDF=ss1, trimS=2, plotit=TRUE)
mod <- oSCR.fit(scrFrame=sf1, ssDF=ss1, trimS=4, plotit=TRUE)
mod <- oSCR.fit(scrFrame=sf1, ssDF=ss1, trimS=6, plotit=TRUE)
mod <- oSCR.fit(scrFrame=sf1, ssDF=ss1, trimS=NULL, plotit=TRUE) #DEFAULT

\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (5.5,-2) {\includegraphics[height=1.5in]{trim.png}}; \end{tikzpicture}

\texttt{oSCR} - Model fitting

mod <- oSCR.fit(model,       # model formulation
                scrFrame,    # the scrFrame object
                ssDF,        # the ssDF object
                encmod,      # the detection function model
                trimS,       # local evaluation distance
                start.vals,  # parameter starting values
                predict,     # predict desnity
                ...)         # a few other options

\normalsize \texttt{start.vals}:

Getting starting values

For example:

sf1 <- subFrame(rbs.sf,1)
ss1 <- rbs.ss[1]
(oSCR.fit(model=list(D~1, p0~1, sig~1), scrFrame = sf1, 
          ssDF = ss1, getStarts = T))
(oSCR.fit(model=list(D~1, p0~t, sig~1), scrFrame = sf1, 
                ssDF = ss1, getStarts = T))

\texttt{oSCR} - Model fitting

mod <- oSCR.fit(model,       # model formulation
                scrFrame,    # the scrFrame object
                ssDF,        # the ssDF object
                encmod,      # the detection function model
                trimS,       # local evaluation distance
                start.vals,  # parameter starting values
                predict,     # predict desnity
                ...)         # a few other options

\normalsize \texttt{predict}:

\texttt{oSCR} - Model fitting with the \textit{rbs} data

Takes $\sim$ 7 mins, can get the model fits here: data(rbs.mods))

sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4))
ss.sub <- rbs.ss[c(2,4)]
st <- c(-3.4, 0.04, 0.08, -1, -0.08)
#NULL model (SCR0) 
m0 <- oSCR.fit(model=list(D~1,p0~1, sig~1), scrFrame=sf.sub,
               ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4)])

\texttt{oSCR} - Model fitting with the \textit{rbs} data

Takes $\sim$ 7 mins, can get the model fits here: data(rbs.mods))

sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4))
ss.sub <- rbs.ss[c(2,4)]
st <- c(-3.4, 0.04, 0.08, -1, -0.08)
#NULL model (SCR0) 
m0 <- oSCR.fit(model=list(D~1,p0~1, sig~1), scrFrame=sf.sub,
               ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4)])

#session-specific desnsity
m1 <- oSCR.fit(model=list(D~session,p0~1, sig~1), scrFrame=sf.sub,       
               ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4,5)])

\texttt{oSCR} - Model fitting with the \textit{rbs} data

Takes $\sim$ 7 mins, can get the model fits here: data(rbs.mods))

sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4))
ss.sub <- rbs.ss[c(2,4)]
st <- c(-3.4, 0.04, 0.08, -1, -0.08)
#NULL model (SCR0) 
m0 <- oSCR.fit(model=list(D~1,p0~1, sig~1), scrFrame=sf.sub,
               ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4)])

#session-specific desnsity
m1 <- oSCR.fit(model=list(D~session,p0~1, sig~1), scrFrame=sf.sub,       
               ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4,5)])

#session-specific sigma
m2 <- oSCR.fit(model=list(D~1,p0~1, sig~session), scrFrame=sf.sub,       
               ssDF=ss.sub, trim=4, start.vals = st[c(1,2,3,4)])

\texttt{oSCR} - Model fitting with the \textit{rbs} data

Takes $\sim$ 7 mins, can get the model fits here: data(rbs.mods))

sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4))
ss.sub <- rbs.ss[c(2,4)]
st <- c(-3.4, 0.04, 0.08, -1, -0.08)
#NULL model (SCR0) 
m0 <- oSCR.fit(model=list(D~1,p0~1, sig~1), scrFrame=sf.sub,
               ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4)])

#session-specific desnsity
m1 <- oSCR.fit(model=list(D~session,p0~1, sig~1), scrFrame=sf.sub,       
               ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4,5)])

#session-specific sigma
m2 <- oSCR.fit(model=list(D~1,p0~1, sig~session), scrFrame=sf.sub,       
               ssDF=ss.sub, trim=4, start.vals = st[c(1,2,3,4)])

#session-specific density & sigma 
m3 <- oSCR.fit(model=list(D~session,p0~1, sig~session), scrFrame=sf.sub, 
               ssDF=ss.sub, trim=4, start.vals = st[c(1,2,3,4,5)])

\texttt{oSCR} - Model output

data(rbs.mods)
#NULL model (SCR0) 
m0

\texttt{oSCR} - Model output

#session-specific desnsity
m1

\texttt{oSCR} - Model output

#session-specific sigma
m2

\texttt{oSCR} - Model output

#session-specific density & sigma 
m3

\texttt{oSCR} - Model output

#session-specific density & sigma 
m3

\normalsize

\texttt{oSCR} - Model selection

oSCR has some post processing and model selection functions:

\texttt{oSCR} - Model selection

oSCR has some post processing and model selection functions:

(fl <- fitList.oSCR(x,            # list of fitted models
                    rename))      # if TRUE models given sensible names

\texttt{oSCR} - Model selection

oSCR has some post processing and model selection functions:

(fl <- fitList.oSCR(list(m0,m1,m2,m3),
                    rename=T))

\texttt{oSCR} - Model selection

oSCR has some post processing and model selection functions:

ms <- modSel.oSCR(fl)
ms$aic.tab

\texttt{oSCR} - Model selection

oSCR has some post processing and model selection functions:

ms <- modSel.oSCR(fl)
ms$coef.tab

\texttt{oSCR} - Model selection

ms

\texttt{oSCR} - Model selection

oSCR has some post processing and model selection functions:

\texttt{oSCR} - Model selection

oSCR has some post processing and model selection functions:

(ma <- ma.coef(ms))

In class exercise: Ocelot data

\vspace{2.5cm}

\begin{center} \Huge The \textcolor{mLightBrown}{Ocelot} data

\footnotesize photo: http://felid-tag.org/ocelot/ \end{center}

\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (0.5, 4.01) {\includegraphics[height=1.5in]{Ocelot_area.png}}; \node[inner sep=0pt] (one) at (10.1,-1.5) {\includegraphics[height=0.8in]{ocelot.jpg}}; \end{tikzpicture}

In class exercise: Ocelot data

\small

Access the ocelot data (data(ocelot)) and, in small groups:

  1. Make an scrFrame for the 2-session ocelot data

    • data2oscr(), make.scrFrame()
  2. Make a state space with a 2000m buffer and 500m resolution

    • make.ssDF(), plot.ssDF()
  3. Estimate density (/100 km^2) and sigma for the simplest SCR model

    • oSCR.fit()
  4. Fit 4 models to assess variation in density and/or sigma by session

  5. Which of theses 4 models is better supported by AIC

    • fitList.oSCR(), modSel.oSCR(), ma.coef()

In class exercise: Ocelot data

  1. Make an scrFrame for the 2-session ocelot data
data(ocelot)

# convert 'secr' format to objects for oSCR
ocelot <-data2oscr(rbind(edf1,edf2),       # encounter data file
                   K=c(44,96),             # occasions per session
                   ntraps=c(23,23),        # traps per session
                   tdf=list(tdf1,tdf2),    # trap deployment files (a list)
                   remove.zeros=TRUE,      # remove uncaptured inds
                   remove.extracaps=TRUE)  # turn >1 to 1

# make the scrFrame
ocelot.sf <- make.scrFrame(caphist = ocelot$y3d,
                           traps = ocelot$traplocs,
                           trapOperation = ocelot$trapopp,
                           type="scr")

In class exercise: Ocelot data

  1. Make an scrFrame for the 2-session ocelot data
par(mfrow=c(1,2), oma=c(0,0,0,0),mar=c(1,1,1,1))
plot(ocelot.sf, ax=FALSE)

In class exercise: Ocelot data

  1. Make a state space with a 2000m buffer and 500m resolution
# make a state-space
ocelot.ss <- make.ssDF(ocelot.sf, buffer=2000, res = 500)
par(mfrow=c(1,2))
plot(ocelot.ss,ocelot.sf)

In class exercise: Ocelot data

  1. Estimate density (/100 km^2) and sigma for the simplest SCR model
data(ocelot.mods)
# fit the null (default!) model
m0 <- oSCR.fit(model=list(D ~ 1, p0 ~ 1, sig~1), # model
               scrFrame = ocelot.sf,             # scrFrame
               ssDF = ocelot.ss,                 # ssDF
               trimS = 1000, se=FALSE))
m0

In class exercise: Ocelot data

  1. Fit 4 models to assess variation in density and/or sigma by session
# NULL
m0 <- oSCR.fit(model=list(D ~ 1, p0 ~ 1, sig~1), scrFrame = ocelot.sf, 
               ssDF = ocelot.ss, trimS = 1000)

# D ~ session only
m1 <- oSCR.fit(model=list(D ~ session, p0 ~ 1, sig~1), scrFrame = ocelot.sf,
               ssDF = ocelot.ss, trimS = 1000)

# sig ~ session only
m2 <- oSCR.fit(model=list(D ~ 1, p0 ~ 1, sig~session), scrFrame = ocelot.sf,
               ssDF = ocelot.ss, trimS = 1000)

# D ~ sesison AND sig ~ session
m3 <- oSCR.fit(model=list(D ~ session, p0 ~ 1, sig~session), scrFrame = ocelot.sf,
               ssDF = ocelot.ss, trimS = 1000)

In class exercise: Ocelot data

  1. Which of theses 4 models is better supported by AIC
# make a 'fit list'
ocelot.fl <- fitList.oSCR(list(m0,m1,m2,m3), rename = TRUE)

# compare models using AIC
ocelot.ms <- modSel.oSCR(ocelot.fl)
ocelot.ms$aic.tab


jaroyle/oSCR documentation built on Sept. 23, 2023, 12:46 p.m.